package com.free.bsf.metric.dal.auto;


import java.util.Date;
import com.free.bsf.core.util.ConvertUtils;
import com.free.bsf.core.db.DbConn;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.*;
import com.free.bsf.metric.model.auto.*;

/**
 * tb_sys_config 表自动dal映射,不要手工修改
 * 
 * @author 车江毅
 * @since 2023-04-03 16:21:07
 * 自动生成: https://gitee.com/makejava/EasyCode/wikis/
 */
public class tb_sys_config_base_dal {

    public boolean add(DbConn conn, tb_sys_config_model model) {
        val par = new Object[]{
            /***/
            model.m_key,
            /***/
            model.m_value,
            /***/
            model.create_time,
            /***/
            model.update_time,
            /**备注*/
            model.remark
        };
        int rev = conn.executeSql("insert into tb_sys_config(m_key,m_value,create_time,update_time,remark)" +
                "values(?,?,?,?,?)", par);
        return rev == 1;
    }

    public boolean edit(DbConn conn, tb_sys_config_model model) {
       val par = new Object[]{
           /***/
            model.m_key,
           /***/
            model.m_value,
           /***/
            model.create_time,
           /***/
            model.update_time,
           /**备注*/
            model.remark,
            model.id
        };
        int rev = conn.executeSql("update tb_sys_config set m_key=?,m_value=?,create_time=?,update_time=?,remark=? where id=?", par);
        return rev == 1;

    }

    public boolean delete(DbConn conn, Integer id) {
        val par = new Object[]{id};
        String Sql = "delete from tb_sys_config where id=?";
        int rev = conn.executeSql(Sql, par);
        if (rev == 1) {
            return true;
        } else {
            return false;
        }
    }

    public tb_sys_config_model get(DbConn conn, Integer id) {
        val par = new Object[]{id};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from tb_sys_config s where s.id=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public ArrayList<tb_sys_config_model> list(DbConn conn) {
        val rs = new ArrayList<tb_sys_config_model>();
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from tb_sys_config s ");
        val ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(createModel(dr));
            }
        }
        return rs;
    }

    public tb_sys_config_model createModel(Map<String, Object> dr) {
        val o = new tb_sys_config_model();
        /***/
        if (dr.containsKey("id")) {
            o.id = ConvertUtils.convert(dr.get("id"),Integer.class);
        }
        /***/
        if (dr.containsKey("m_key")) {
            o.m_key = ConvertUtils.convert(dr.get("m_key"),String.class);
        }
        /***/
        if (dr.containsKey("m_value")) {
            o.m_value = ConvertUtils.convert(dr.get("m_value"),String.class);
        }
        /***/
        if (dr.containsKey("create_time")) {
            o.create_time = ConvertUtils.convert(dr.get("create_time"),Date.class);
        }
        /***/
        if (dr.containsKey("update_time")) {
            o.update_time = ConvertUtils.convert(dr.get("update_time"),Date.class);
        }
        /**备注*/
        if (dr.containsKey("remark")) {
            o.remark = ConvertUtils.convert(dr.get("remark"),String.class);
        }
        return o;
    }
}


